package gogsci

import "time"

type PayloadCommit struct {
	ID        string       `json:"id"`
	Message   string       `json:"message"`
	URL       string       `json:"url"`
	Author    *PayloadUser `json:"author"`
	Committer *PayloadUser `json:"committer"`

	Added    []string `json:"added"`
	Removed  []string `json:"removed"`
	Modified []string `json:"modified"`

	Timestamp time.Time `json:"timestamp"`
}

type PayloadUser struct {
	Name     string `json:"name"`
	Email    string `json:"email"`
	UserName string `json:"username"`
}

type PushPayload struct {
	Ref           string           `json:"ref"`
	RefType       string           `json:"ref_type"`
	DefaultBranch string           `json:"default_branch"`
	Before        string           `json:"before"`
	After         string           `json:"after"`
	Action        string           `json:"action"`
	CompareURL    string           `json:"compare_url"`
	Commits       []*PayloadCommit `json:"commits"`
	Repo          *Repository      `json:"repository"`
	Pusher        *User            `json:"pusher"`
	Sender        *User            `json:"sender"`
	Release       *struct {
		TagName         string `json:"tag_name"`
		TargetCommitish string `json:"target_commitish"`
	} `json:"release"`
}

// User represents a API user.
type User struct {
	ID        int64  `json:"id"`
	UserName  string `json:"username"` // LEGACY [Gogs 1.0]: remove field(s) for backward compatibility
	Login     string `json:"login"`
	FullName  string `json:"full_name"`
	Email     string `json:"email"`
	AvatarUrl string `json:"avatar_url"`
}

// Permission represents a API permission.
type Permission struct {
	Admin bool `json:"admin"`
	Push  bool `json:"push"`
	Pull  bool `json:"pull"`
}

// Repository represents a API repository.
type Repository struct {
	ID            int64       `json:"id"`
	Owner         *User       `json:"owner"`
	Name          string      `json:"name"`
	FullName      string      `json:"full_name"`
	Description   string      `json:"description"`
	Private       bool        `json:"private"`
	Fork          bool        `json:"fork"`
	Parent        *Repository `json:"parent"`
	Empty         bool        `json:"empty"`
	Mirror        bool        `json:"mirror"`
	Size          int64       `json:"size"`
	HTMLURL       string      `json:"html_url"`
	SSHURL        string      `json:"ssh_url"`
	CloneURL      string      `json:"clone_url"`
	Website       string      `json:"website"`
	Stars         int         `json:"stars_count"`
	Forks         int         `json:"forks_count"`
	Watchers      int         `json:"watchers_count"`
	OpenIssues    int         `json:"open_issues_count"`
	DefaultBranch string      `json:"default_branch"`
	Created       time.Time   `json:"created_at"`
	Updated       time.Time   `json:"updated_at"`
	Permissions   *Permission `json:"permissions,omitempty"`
}

// 鉴别是 release：   "action": "published",
// 鉴别是 tag：   "ref_type": "tag",
// 鉴别是 推送： before after != ""
